package com.futures.investm.activity;

import android.os.Bundle;

import com.aries.ui.view.title.TitleBarView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.futures.investm.R;
import com.futures.investm.adapter.NewsAdapter;
import com.futures.investm.constant.Api;
import com.futures.investm.entity.RealTimeInfo;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.vise.xsnow.http.request.GetRequest;

import java.util.ArrayList;

import tech.com.commoncore.app.FastManager;
import tech.com.commoncore.base.BaseRefreshLoadActivity;
import tech.com.commoncore.entity.BaseTResp;

/**
 * 热点新闻
 */
public class NewsActivity extends BaseRefreshLoadActivity<RealTimeInfo> {

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText("国际快讯")
                .setStatusBarLightMode(false);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_news;
    }

    @Override
    public void initView(Bundle savedInstanceState) {

    }

    @Override
    public BaseQuickAdapter<RealTimeInfo, BaseViewHolder> getAdapter() {
        return new NewsAdapter();
    }

    @Override
    public void loadData(int page) {

        /**
         *   ViseHttp.GET(Api.FOREIGN_URL)
         *                 .addParam("cid", "162")
         *                 .request(new ACallback<BaseTResp<ArrayList<ForeignEntity>>>() {
         *             @Override
         *             public void onSuccess(BaseTResp<ArrayList<ForeignEntity>> data) {
         *                 if (1 == data.code) {
         *                     if (data.data.size()>=4){
         *                         mForeignAdapter.replaceData(data.data.subList(0,4));
         *                     }else {
         *                         mForeignAdapter.replaceData(data.data);
         *                     }
         *
         *                 } else {
         * //                            ToastUtils.showToast("请求数据失败");
         *                 }
         *             }
         *
         *             @Override
         *             public void onFail(int errCode, String errMsg) {
         *
         *             }
         *         });
         */


        if (page == 0) {
            GetRequest request = ViseHttp.GET(Api.FOREIGN_URL)
                    .addParam("cid","162");

            request.request(new ACallback<BaseTResp<ArrayList<RealTimeInfo>>>() {
                @Override
                public void onSuccess(BaseTResp<ArrayList<RealTimeInfo>> data) {
                    FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), data.data, null);

                }

                @Override
                public void onFail(int errCode, String errMsg) {
                    FastManager.getInstance().getHttpRequestControl().httpRequestError(getIHttpRequestControl(), new Throwable(errMsg));
                }
            });
        } else {
            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), new ArrayList<>(), null);
        }
    }
}
